﻿using DemoQLKhoSX.DatabaseAccessLayer;
using DemoQLKhoSX.EntityClasses;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

namespace DemoQLKhoSX.BusinessLogicLayer
{
    public class NhapBLO
    {
        private NhapDAO _NhapDAO;
        private NhaCungCapBLO _NhaCungCapBLO = new NhaCungCapBLO();
        private ThuKhoBLO _thukhoBLO = new ThuKhoBLO();
        private HangBLO _hangBLO = new HangBLO();

        public NhapBLO()
        {
            _NhapDAO = new NhapDAO();
        }

        public List<NhapEntity> getNhapByID(string id)
        {
            List<NhapEntity> Nhap = new List<NhapEntity>();
            DataTable tbl = new DataTable();
            tbl = _NhapDAO.searchByID(id);

            if (tbl != null)
                foreach (DataRow r in tbl.Rows)
                {
                    NhapEntity rNhap = new NhapEntity();
                    rNhap.IDNhap = id;
                    rNhap.IDHang = _hangBLO.getHangByID(r["IDHang"].ToString());
                    rNhap.IDNCC = _NhaCungCapBLO.getNhaCungCapByID(r["IDNCC"].ToString());
                    rNhap.NgayNhap = Convert.ToDateTime(r["NgayNhap"].ToString());
                    rNhap.IDThuKho = _thukhoBLO.getThuKhoByID(r["IDThuKho"].ToString());
                    rNhap.SoLuongNhap = Convert.ToInt32(r["SoLuongNhap"].ToString());
                }
            return Nhap;
        }
        public bool InsertNhap(string idnhap, string idthukho, string idncc, string idhang, DateTime ngaynhap, int soluongnhap)
        {
            bool rs = false;
            rs = _NhapDAO.addNhap(idnhap, idthukho, idncc, idhang, ngaynhap, soluongnhap);

            return rs;
        }
    }
}
